package com.ourteam.education.api;

import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

import com.ourteam.education.dao.CampusDAOQueryBean;
import com.ourteam.education.domain.CampusBean;
import com.ourteam.frame.web.AbstractSearchModel;

public class CampusSearchBean extends AbstractSearchModel<CampusDAOQueryBean> {

	private String campusName;

	private String campusAddress;

	private String[] status;

	private String[] campusType;

	public String getCampusName() {
		return campusName;
	}

	public void setCampusName(String campusName) {
		this.campusName = campusName;
	}

	public String getCampusAddress() {
		return campusAddress;
	}

	public void setCampusAddress(String campusAddress) {
		this.campusAddress = campusAddress;
	}

	public String[] getStatus() {
		return status;
	}

	public void setStatus(String[] status) {
		this.status = status;
	}

	public String[] getCampusType() {
		return campusType;
	}

	public void setCampusType(String[] campusType) {
		this.campusType = campusType;
	}

	@Override
	public String getMappedDAOField(String aProperty) {
		return CampusBean.getMappedDAOField(aProperty);
	}

	@Override
	protected void doBuildQueryBean(CampusDAOQueryBean queryBean) throws Exception {

		CampusDAOQueryBean.Criteria criteria = queryBean.createCriteria();

		if (StringUtils.isNoneBlank(this.campusName)) {
			criteria.andCampusNameLike(campusName);
		}

		if (StringUtils.isNoneBlank(this.campusAddress)) {
			criteria.andCampusAddressLike(campusAddress);
		}

		if (ArrayUtils.isNotEmpty(this.campusType)) {
			criteria.andCampusTypeIn(campusType);
		}

		if (ArrayUtils.isNotEmpty(this.status)) {
			criteria.andStatusIn(status);
		}

	}

}
